package com.hf.action;

import java.io.IOException;
import java.util.*;
import tool.ClientTool;
import com.base.bean.*;
import com.base.service.*;

/**
 * ajax 验证电话号码的格式 以及是否唯一<br>
 * resultState: 1成功 -1电话格式错误 -2电话重复 -3姓名有非汉子 -4姓名包含称呼<br>
 * type:2:姓名 1:电话
 * @author chz
 *
 */
public class JsonCheck extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String phoneName; // 电话或姓名
	private int type; // 2:姓名 1:电话
	private int resultState; // 返回状态码 1成功 -1电话格式错误 -2电话重复 -3姓名有非汉子 -4姓名包含称呼
	private String tip;
	private ClientService cs;

	public JsonCheck() {
		// TODO Auto-generated constructor stub
		cs = ClientService.getInstance();
	}



	@Override
	public String execute() {
		this.tip="";
		this.phoneName=(this.phoneName==null?"":this.phoneName.replaceAll("\\s*", ""));	
		
		if (type == 1) {
			resultState = cs.checkPhone(phoneName);
			if (resultState == -1)
				if(!phoneName.equals(""))
					tip = "格式错误";
			if (resultState == -2)
				tip = "号码存在";
			if (resultState > 0){
				resultState=1;
				tip = "验证通过";
			}
		}

		if (type == 2) {
			int result=0;
			try {
				result = ClientTool.isName(phoneName);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if (result == 1){
				resultState=-3;
				if(!phoneName.equals(""))
					tip = "格式有误";
				else
					tip="不能为空";
			}
			else if (result == 2){
				resultState=-4;
				tip = "包含称呼";
			}
			else{
				tip = "验证通过";
				resultState=1;
			}

		}

		return SUCCESS;

	}

	

	public String getTip() {
		return tip;
	}

	public void setTip(String tip) {
		this.tip = tip;
	}

	public String getPhoneName() {
		return phoneName;
	}

	public void setPhoneName(String phoneName) {
		this.phoneName = phoneName;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public int getResultState() {
		return resultState;
	}

	public void setResultState(int resultState) {
		this.resultState = resultState;
	}


}
